
/**
*一个区域和一个实体，鼠标移动进入区域后哪个实体就出现
*mc_mask,mc_btnpad
*/
package kgame5.kgui.kcomp {
	import com.greensock.TweenLite;

	import flash.display.*;
	import flash.events.*;

	public class SmartBtnpad extends EventDispatcher{
	
	
	//___________________PROPERTY___________________
	private var 
		mc:MovieClip,
			mc_btnpad:MovieClip,
			mc_mask:MovieClip;
	
	private var
		TB:Number,//mc_btnpad移动的时候的上部的边界
		BB:Number;//mc_btnpad移动的时候的最下边的边界,这个是0
		
	private var
		MoveDur:Number=0.3;//秒，移动到达目标的时间
		
	//btnpad弹上
	private var bUp:Boolean=false;
	//___________________METHOD______________________
	public function SmartBtnpad(p_mc:MovieClip,dur:Number=0.2){
		mc=p_mc;
		mc_btnpad=mc.mc_btnpad;
		mc_mask=mc.mc_mask;
		
		MoveDur=dur;
		
		TB=-mc_btnpad.height;
		BB=0;
		
		//--!!注意这个最开始就是显示的
		show();
		//hide();
	}
	
	
	public function show(){
		//T.p("smartBtnpad.show()");
		mc.visible=true;
	
		//
		if(mc_mask.stage==null){
			mc_mask.addEventListener(Event.ADDED_TO_STAGE, atsH);
		}else{
			mc_mask.stage.addEventListener(MouseEvent.MOUSE_MOVE, OnStageMouseMove);
		}
		
	}
	private function atsH(e:Event){
		mc_mask.stage.addEventListener(MouseEvent.MOUSE_MOVE, OnStageMouseMove);
	}
	
	public function hide(){
		//T.p("smartBtnpad.hide()");
		mc.visible=false;
		
		//
		if(mc_mask.stage!=null){
			mc_mask.stage.removeEventListener(MouseEvent.MOUSE_MOVE, OnStageMouseMove);
		}
		//不显示的时候直接放回去
		TweenLite.killTweensOf(mc_btnpad);
		mc_btnpad.y=BB;
	}
	private function OnStageMouseMove(e:MouseEvent){
		if(mc.visible==false){
			return;
		}
			
		if(mc_mask.hitTestPoint(e.stageX, e.stageY)){
			if(bUp==false){
				bUp=true;
				TweenLite.to(mc_btnpad,MoveDur,{y:TB});
				//Tween2DX.StartMoveY(mc_btnpad, TB, MoveDur);
			}
		}else{
			if(bUp){
				bUp=false;
				TweenLite.to(mc_btnpad,MoveDur,{y:BB});
				//Tween2DX.StartMoveY(mc_btnpad, BB, MoveDur);
			}
		}
	}
}//end of class
}